/**
 * 
 */
package src.model.gameObject.ability;

import src.model.gameObject.GameObject;
import src.model.gameObject.GameObjectType;
import src.model.gameObject.PlayerGameObject;
import src.model.gameObject.eventBrokers.HealthEventBroker;
import src.model.gameObject.eventInterfaces.HealthPublisher;
import src.model.gameWorld.ActualMap;
import src.model.gameWorld.PlayerLookupTable;
import src.model.gameWorld.Position;

/**
 * <b>Overview</b><br>
 * <p>This ability allows one PlayerGameObject to heal another Unit. It will only heal friendly units, not enemies
 * or neutral objects.</p>
 * <br><br>
 * <b>Responsibilites</b><br>
 * <p>Heal friendly units and only friendly units.</p>
 * <br><br>
 * <b>Collaborators</b>
 * <br>ActualMap - Check for adjacency.<br>
 * <b>Implementor</b> - Tristan Lohman<br>
 * <b>Tester</b> - Brent<br>
 * @author Tristan
 *
 */
public class Heal extends ActiveAbility implements HealthPublisher{

	private ActualMap am;
	/**
	 * Constructs a new Heal Ability and registers it with any appropriate Brokers.
	 * @param pgo The PlayerGameObject that owns this.
	 * @param playerLookup The PlayerLookupTable for this ability.
	 * @param am The ActualMap that this resides on.
	 */
	public Heal(PlayerGameObject pgo, PlayerLookupTable playerLookup, ActualMap am) {
		super(pgo, AbilityType.HEAL, playerLookup);
	}
	
	/**
	 * Upon execution, this will heal any friendly PlayerGameObjects at the first position it is passed.
	 * @param position The Position to heal
	 * @return Whether or not this was successful.
	 */
	public AbilityReturnResult execute(Position... position){
		if (am.adjacent(am.findObject(super.gameObject()), position[0])){
			GameObject unit = am.findObject(position[0], GameObjectType.UNIT);
			int modifyAmount = (int)super.getAttribute(AbilityAttributes.STRENGTH);
			publishHealthModifier(unit, modifyAmount);
			return AbilityReturnResult.SUCCESS;
		}
		return AbilityReturnResult.IMPOSSIBLE;
	}
	
	public void publishHealthModifier(GameObject go, float modifyAmount) {
		HealthEventBroker.notifyModifyHealth(go, modifyAmount);
	}
	
	public boolean queueToMission(Position...position){
		if (position.length == 0)  return false;
		super.gameObject().enqueueAbility(this, position);
		return true;
	}
	
	public void destroySub(){
	}
}
